﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml.Serialization;

namespace Shlook.Common
{
    public class ChatConfiguration
    {
        private const string ConfigFileName = "Shlook.config";
        private static string ConfigPath
        {
            get
            {
                return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ConfigFileName);
            }
        }

        public string ServerURL { get; set; }
        public string ClientURL { get; set; }
        public string ClientDisplayName { get; set; }

        public void Save()
        {
            XmlSerializer ser = new XmlSerializer(typeof(ChatConfiguration));
            using (FileStream stream = new FileStream(ConfigPath, FileMode.Create, FileAccess.ReadWrite))
            {
                ser.Serialize(stream, this);
            }
        }

        public static ChatConfiguration Load()
        {
            XmlSerializer ser = new XmlSerializer(typeof(ChatConfiguration));
            using (FileStream stream = new FileStream(ConfigPath, FileMode.OpenOrCreate, FileAccess.ReadWrite))
            {
                return (ChatConfiguration)ser.Deserialize(stream);
            }
        }
    }
}
